<?php

namespace app\common\letterbusiness\user;

use app\common\mysql\Users as userlvMysql;

/**
 * 会员等级 
 */
class UserLv extends \app\common\letterbusiness\AbstractModel {

    /**
     * 当前用户日常的会员等级是否已满
     */
    public static function dailyLvValue($parmas, $user_id) {
        $total = userlvMysql::name('user_lv_log')->where(array(
                    'user_id' => $user_id,
                    'point_type' => $parmas['point_type'],
                ))
                ->whereTime('log_time', 'today')
                ->sum('change_point');
        if ($total >= $parmas['max']) {
            $parmas['change_lv_value'] = 0;
        }
        return $parmas['change_lv_value'];
    }

    /**
     * 当前任务会员等级是否已满
     */
    public static function taskLv($parmas, $user_id) {
        $where['user_id'] = $user_id;
        $where['source_type'] = $parmas['source_type'];
        if (isset($parmas['source_id']) && !empty($parmas['source_id'])) {
            $where['source_id'] = $parmas['source_id'];
        }
        $total = userlvMysql::name('user_lv_log')->where($where)
                ->sum('change_point');
        if ($parmas['max'] != 0 && $total >= $parmas['max']) {
            $parmas['change_lv_value'] = 0;
        }
        return $parmas['change_lv_value'];
    }

}
